<?php
/**
 * System_Model_Role
 *
 * @author mmxie
 * @copyright Copyright (c) 2009 Green Shore (http://www.iwgame.com)
 * @version $Id: Role.php 906 2011-10-20 02:38:33Z mmxie $
 */
class System_Model_Role extends IG_Model
{

    protected $_data = array(
        'role_id' => null,
        'name' => null,
        'title' => null,
    );



    /**
     * @param int $value
     * @return System_Model_Role
     */
    public function setRoleId($value)
    {
        $this->role_id = (int) $value;
        return $this;
    }

    public function getRoleId()
    {
        return $this->role_id;
    }

    /**
     * @param string $value
     * @return System_Model_Role
     */
    public function setName($value)
    {
        $this->name =  $value;
        return $this;
    }

    public function getName()
    {
        return $this->name;
    }

    /**
     * @param string $value
     * @return System_Model_Role
     */
    public function setTitle($value)
    {
        $this->title =  $value;
        return $this;
    }

    public function getTitle()
    {
        return $this->title;
    }

    protected $_resources;

    /**
     * 获取角色资源
     */
    public function getResources()
    {
        if (!isset($this->_resources)) {
            $this->_resources = $this->getMapper()->getResources();
        }
        return $this->_resources;
    }

    /**
     * 查询角色相关资源
     * @param $id
     */
    public function findResource($id)
    {
        $this->setRoleId($id);
        return $this->getMapper()->findResource($this);
    }

    public function saveResource($resourceIds)
    {
        return $this->getMapper()->saveResource($this, $resourceIds);
    }

    public function getResourceIds($roleId)
    {
        return $this->getMapper()->getResourceIds($roleId);
    }
}